<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>

    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            气密泄露点位统计
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">


        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">产品条码</div>
                    <div class="aui-list-item-input">
                        <input id="barcode"></input>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">点位</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择点位" id="point" value="" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectPoint()"></i>
                </div>
            </li>

        </ul>



    </div>


    <div class=' aui-btn aui-btn-info aui-btn-block' onclick='doSave()'>保存
    </div>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";   //设备唯一号
    var workCenterCode = "";  //生产线编码
    var qualchkitemCode = "";
    var qualchkitemName = "";
    var qualchkitemGid = "";
    //初始化
    apiready = function () {

        $("#barcode").focus();

        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //1:查询产线工序信息
        searchWorkCenterData();

    };

    //产线选择后回调函数
    function setQualchkitem(name) {
        qualchkitemCode = name;
        qualchkitemName = name;
        document.getElementById('point').value = name;
    }


    //查询产线工位信息
    function searchWorkCenterData() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getOpCodeByUniCode";
        var data = {
            values: {
                clientCode: equipUniqueId,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {

                    workCenterCode = myobj.workCenterCode;

                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }


    function goSelectPoint() {
        if (workCenterCode == '' || workCenterCode == null) {
            api.toast({
                msg: "设备唯一号未配置产线！",
                duration: 3000
            });
            return
        }
        api.openWin({
            name: 'usmSelectPoint',
            url: 'usmSelectPoint.html',
            pageParam: {
                workCenterCode: workCenterCode,
                name: "paAirtightLeakage",
            }
        });


    }
    //保存
    function doSave() {

        var barcode_web = document.getElementById('barcode').value;

        if (barcode_web == null || barcode_web == "") {

            api.toast({
                msg: "请先扫描产品条码！",
                duration: 3000
            });
            return
        }

        var qualchkitemCode = document.getElementById('point').value;


        if (qualchkitemCode == null || qualchkitemCode == "") {

            api.toast({
                msg: "请先选择点位！",
                duration: 3000
            });
            return
        }

        var uns = localStorage.getItem('un');
        var serverUrls = localStorage.getItem('serverUrl');
        var urls = serverUrls + "/app/savePoint";
        var data = {
            values: {
                barcode: barcode_web,
                qualchkitemCode: qualchkitemCode,
                workCenterCode:workCenterCode,
                un: uns,
            }
        };

        api.ajax({
            url: urls,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == 0) {
                    alert('保存成功！')
                    document.getElementById('point').value = "";
                    document.getElementById('barcode').value = "";

                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            }
        });





    }






    //产品条码监听回车事件
    $("#barcode").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            doSave()
        }
    });



    //返回按钮
    function closeWin() {
        // 
        if (api.pageParam.barcode == undefined) {
            api.closeWin({});
        } else {
            api.closeToWin({ name: api.pageParam.name });
            api.execScript({
                name: api.pageParam.name,
                script: 'refreshData()'
            });
        }
    }


</script>

</html>